import axios from 'axios'
import { getUser } from './utils'


const service = axios.create({
  baseURL: '',
  timeout: 50000,
  headers: {}
})

service.interceptors.request.use(config => {
  const user = getUser()
  if (user) {
    config.headers['Authorization'] = user.auth
  }
  config.headers['Content-Type'] = 'application/json'

  return config
}, error => {
  return Promise.reject(error)
})

service.interceptors.response.use(response => {
  const { data } = response
  return data
}, error => {
  return Promise.reject(error)
})
export default service